﻿using System;
using System.Linq;
using System.Collections.ObjectModel;
using RiskMan.DataClass.Models;
using RiskMan.DataClass;
using RiskMan.DataClass.Stops;

namespace RiskMan.Config
{
    public class History
    {
        private Data _data;

        public History ( DataClass.Data _dataProvider )
        {
            this._data = _dataProvider;
        }

        #region Загрузка

        public void Load ( )
        {
            _data.StopList = GetStopList( );

            _data.T2QItems.Clear( );
            var lis = GetQuikSettings();

            for ( int i = 0; i < lis.Count; i++ )
                _data.T2QItems.Add( lis[i] );

        }


        private ObservableCollection<QuikItem> GetQuikSettings ( )
        {
            return ( QuikItems ) XmlHistory.GetXmlData( XmlHistory.FilenameQuikitems );
        }

        private ObservableCollection<StopsModel> GetStopList ( )
        {
            return ( ObservableCollection<StopsModel> ) XmlHistory.GetXmlData( XmlHistory.FilenameStoplist );
        }

        #endregion

        #region Сохранение

        public void Save ( )
        {
            SetStopList( _data.StopList );
            SetQuikSettings( _data.T2QItems );

        }


        private void SetQuikSettings ( QuikItems quikItems )
        {
            XmlHistory.SetXmlData( XmlHistory.FilenameQuikitems, ( Object ) quikItems );
        }

        private void SetStopList ( ObservableCollection<StopsModel> observableCollection )
        {
            XmlHistory.SetXmlData( XmlHistory.FilenameStoplist, ( Object ) ( observableCollection.ToList( ) ) );
        }

        #endregion
    }
}